package com.gpnu.crm.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.gpnu.crm.domain.Customer;
import com.gpnu.crm.query.CustomerQueryObject;
import com.gpnu.crm.service.ICustomerService;
import com.gpnu.crm.service.ISystemDictionaryService;


@Controller
@RequestMapping("/customer")
public class CustomerController {
	  @Autowired
	  private ICustomerService customerService;
	  @Autowired
	  private ISystemDictionaryService dictionaryService;
	  	  
	  @RequestMapping("/list")
	  public String list(@org.springframework.web.bind.annotation.ModelAttribute("qo") CustomerQueryObject qo, Model model)
	  {
	    qo.setOrderby("c.inputTime desc");
	    
	    model.addAttribute("pageInfo", customerService.query(qo));
	    model.addAttribute("jobs", dictionaryService.queryItemByParentSn("job"));
	    model.addAttribute("sources", dictionaryService.queryItemByParentSn("source"));
	    model.addAttribute("types", dictionaryService.queryItemByParentSn("communicationMethod"));
	    return "customer/list";
	  }
	  
	  @RequestMapping("/saveOrUpdate")
	  @ResponseBody
	  public Object saveOrUpdate(Customer entity) {
	    customerService.saveOrUpdate(entity);
	    return "redirect:/customer/list.do";
	  }
	  
	  @RequestMapping("/updateStatus")
	  @ResponseBody
	  public Object updateStatus(Customer entity) {
	    customerService.updateStatus(entity);
	    return "redirect:/customer/list.do";
	  }

}
